package com.scuec.trainingmanagementsys.mapper;

import com.scuec.trainingmanagementsys.entity.WeeklyAssessment;
import org.apache.ibatis.annotations.*;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;
import java.util.Map;

public interface WeeklyAssessmentMapper {
    // 增加周评估记录
    @Insert("INSERT INTO weeklyassessment (weeklyAssessmentContent, teacherID, wsCreateTime, weeklyReportID) " +
            "VALUES (#{weeklyAssessmentContent}, #{teacherID}, #{wsCreateTime}, #{weeklyReportID})")
    int addWeeklyAssessment(WeeklyAssessment weeklyAssessment);

    // 删除周评估记录
    @Delete("DELETE FROM weeklyassessment WHERE weeklyassessmentid = #{weeklyAssessmentID}")
    int deleteWeeklyAssessmentById(Integer weeklyAssessmentID);

    // 根据ID查找周评估记录
    @Select("SELECT * FROM weeklyassessment WHERE weeklyassessmentid = #{weeklyAssessmentID}")
    WeeklyAssessment findWeeklyAssessmentById(Integer weeklyAssessmentID);

    // 查找所有周评估记录
    @Select("SELECT * FROM weeklyassessment")
    List<WeeklyAssessment> findAllWeeklyAssessments();

    // 根据教师ID查找周评估记录
    @Select("SELECT * FROM weeklyassessment WHERE teacherid = #{teacherID}")
    List<WeeklyAssessment> findWeeklyAssessmentsByTeacherId(Integer teacherID);

    // 修改周评估记录
    @Update("UPDATE weeklyassessment " +
            "SET weeklyassessmentcontent = #{weeklyAssessmentContent}, " +
            "teacherid = #{teacherID}, " +
            "wscreatetime = #{wsCreateTime}, " +
            "weeklyreportid = #{weeklyReportID} " +
            "WHERE weeklyassessmentid = #{weeklyAssessmentID}")
    int updateWeeklyAssessment(WeeklyAssessment weeklyAssessment);

    // 根据周报ID查找周评估记录
    @Select("SELECT * FROM weeklyassessment WHERE weeklyreportid = #{weeklyReportID}")
    List<WeeklyAssessment> findWeeklyAssessmentsByWeeklyReportID(Integer weeklyReportID);

    // 根据周报ID查找周评估记录，并关联教师表获取教师姓名
    @Select("SELECT w.weeklyassessmentid, w.weeklyassessmentcontent, w.wscreatetime, t.teachername " +
            "FROM weeklyassessment w " +
            "LEFT JOIN teacher t ON w.teacherid = t.teacherid " +
            "WHERE w.weeklyreportid = #{weeklyReportID}")
    List<Map<String, Object>> findWeeklyAssessmentsByWeeklyReportIDWithDetails(Integer weeklyReportID);

    @Select("SELECT " +
            "w.weeklyAssessmentID, w.weeklyAssessmentContent, w.wsCreateTime, " +
            "t.teacherName " +
            "FROM weeklyassessment w " +
            "LEFT JOIN teacher t ON w.teacherID = t.teacherID " +
            "WHERE w.weeklyReportID = #{weeklyReportID}")
    List<Map<String, Object>> getCommentsByReportId(Integer weeklyReportID);

    @Select("SELECT * FROM weeklyassessment WHERE weeklyreportid = #{reportId}") // 添加该方法的SQL映射
    List<WeeklyAssessment> getAssessmentsByReportId(Integer reportId);
}